package cn.lvji.springboot.learn5.rest;


import cn.lvji.springboot.learn5.entity.Scenic;
import cn.lvji.springboot.learn5.service.ScenicService;
import cn.lvji.springboot.learn5.vo.LayuiGridResponse;
import cn.lvji.springboot.learn5.vo.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 景区: 后端controller类
 *
 * @author generator
 */
@RestController
public class ScenicController {

    private ScenicService scenicServiceImpl;

    @Autowired
    private ScenicController(ScenicService scenicServiceImpl) {
        this.scenicServiceImpl = scenicServiceImpl;
    }

    /**
     * 新增景区
     *
     * @param scenic 实体对象
     * @return response
     */
    @PostMapping("/pt/scenic")
    public Response<Void> save(@RequestBody Scenic scenic) {
        return scenicServiceImpl.save(scenic);
    }


    /**
     * 查询景区
     *
     * @param id 主键
     * @return response
     */
    @GetMapping("/pb/scenic/{id}")
    public Response<Scenic> get(@PathVariable("id") Long id) {
        Response<Scenic> res = new Response<Scenic>();
        Scenic scenic = scenicServiceImpl.get(id);
        res.setData(scenic);
        return res;
    }


    /**
     * 分页查询景区
     *
     * @param page 当前页
     * @param limit 每页条数
     * @param name 景区名称
     * @param createTime 创建时间
     */
    @GetMapping("/pb/scenic/action/search")
    public LayuiGridResponse<Scenic> list(int page, int limit, String name, @RequestParam(value = "createTime",defaultValue ="1990-01-01") Date createTime) {
        return scenicServiceImpl.list(page, limit, name, createTime);
    }


    /**
     * 更新景区
     *
     * @param param 实体对象
     * @return response
     */
    @PutMapping("/pt/scenic")
    public Response<Void> update(@RequestBody Scenic param) {
        return scenicServiceImpl.update(param);
    }


    /**
     * 删除景区
     *
     * @param id 主键
     * @return response
     */
    @DeleteMapping("/pv/scenic/{id}")
    public Response<Void> delete(@PathVariable("id") Long id) {
        return scenicServiceImpl.delete(id);
    }


}